import antfu from '@antfu/eslint-config'
import { FlatCompat } from '@eslint/eslintrc'
import pluginVue from 'eslint-plugin-vue'

const compat = new FlatCompat()

export default antfu(
  {
    typescript: true,
    vue: true,
    jsonc: true,
    yaml: true,
    unocss: true,

    formatters: {
      css: true,
      html: true,
      markdown: 'prettier'
    },

    stylistic: {
      indent: 2,
      quotes: 'single'
    },

    rules: {
      // 尾随逗号
      'style/comma-dangle': 'off',

      // 禁止使用console
      'no-console': 'off',

      // 禁止使用process
      'node/prefer-global/process': 'off',

      'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],

      'no-multiple-empty-lines': ['error', { max: 1 }],

      'style/max-statements-per-line': ['error', { max: 100 }],

      'style/arrow-parens': ['error', 'always'],

      'max-len': [
        'error',
        {
          code: 100,
          tabWidth: 2,
          ignoreComments: true,
          ignoreStrings: true,
          ignoreUrls: true,
          ignoreTemplateLiterals: true,
          ignoreRegExpLiterals: true,
          ignoreTrailingComments: true,

          // 正则匹配class过长或者svg中的d多长
          ignorePattern: '(class|d)=(\'|\").*(\'|\")'
        }
      ],

      'style/quote-props': ['error', 'as-needed'],

      // 标签闭合位置换行
      'style/jsx-closing-bracket-location': ['error', 'line-aligned'],

      'lines-around-comment': [
        'error',
        {
          beforeBlockComment: true,
          afterBlockComment: false,
          beforeLineComment: true,
          afterLineComment: false,
          allowBlockStart: true,
          allowBlockEnd: true,
          allowObjectStart: true,
          allowObjectEnd: true,
          allowArrayStart: true,
          allowArrayEnd: true
        }
      ],

      'vue/html-self-closing': [
        'error',
        {
          html: {
            normal: 'always',
            void: 'always',
            component: 'always'
          }
        }
      ]
    },

    ignores: ['visualizer.html']
  },

  ...pluginVue.configs['flat/recommended'],

  ...compat.config({
    extends: ['./types/autoImport/.eslintrc-auto-import.json']
  })
)
